1 // Equipo Poncho, Carriel y Ruana
23 template <class T
> string
toStr(const T
&x
)
24 { stringstream s
; s
<< x
; return s
.str(); }
25 template <class T
> int toInt(const T
&x
)
26 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
28 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
30 #define D(x) cout << #x " = " << (x) << endl;
32 const double EPS
= 1e-9;
34 int cmp(double x
, double y
= 0, double tol
= EPS
) {
35 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
38 const int MAXBASES
= 105, oo
= 1 << 28;
47 for (int i
= 0; i
< 16; ++i
){
48 printf("%d", !!(x
& (1 << i
)));
53 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
58 for (int i
= 0; i
< B
; ++i
) {
59 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
60 if (dp
[mask
] >= oo
) continue;
62 dp
[mask
| base
] = min(dp
[mask
| base
], dp
[mask
] + 1);
68 while (scanf("%d %d", &B
, &D
) == 2) {
69 if (B
== 0 and D
== 0) break;
70 for (int i
= 0; i
< B
; ++i
) {
73 int k
; scanf("%d", &k
);
75 int x
; scanf("%d", &x
); x
--;
80 for (int j
= 0; j
< D
; ++j
) {
82 int k
; scanf("%d", &k
);
84 int x
; scanf("%d", &x
); x
--;
89 if (ans
>= oo
) ans
= 0;
92 if (j
+ 1 < D
) printf(" ");